//
//  SEGQueryFeedbackViewModel.m
//  SEGViewModel
//
//  Created by 山刘 on 2020/6/1.
//

#import "SEGQueryFeedbackViewModel.h"

@implementation SEGQueryFeedbackViewModel
#pragma mark - business
-(void)requestDictionaryInfoByCode:(void(^)(BOOL isSuccessed,NSString * content))completed{
    [[SEGFindDictionaryInfoManagr sharedManager] requestDictionaryInfoByCode:@"service_qq" completed:^(BOOL isSuccessed, id  _Nonnull result, NSString * _Nonnull codeType, NSString * _Nonnull errorMessage) {
        if (!isSuccessed) {
            completed(NO,nil);
            return;
        }
        if (![result valueForKey:@"data"]) {
            completed(NO,nil);
            return;
        }
        
        SEGDictionaryInfoModel *data = [SEGDictionaryInfoModel yy_modelWithDictionary:[result valueForKey:@"data"]];
        NSArray* arr = [data.result.firstObject.value componentsSeparatedByString:@","];
        
        if (arr.count > 0 && arr.count % 2 != 0) {
            NSMutableArray* arrM = [NSMutableArray arrayWithArray:arr];
            [arrM addObject:@" "];
            arr = [arrM copy];
        }
        
        if (arr.count <= 0) {
            completed(NO,nil);
            return;
        }
        NSString* content = [NSString stringWithFormat:@"如果您在试用%@时遇到问题或者有好的建议，\n欢迎加入我们的用户反馈QQ群：\n",kAppName];
        
        //判断奇偶数
        if (arr.count % 2 == 0) {
            for (NSInteger i = 0; i < arr.count; i = i + 2) {
                NSString* str = [NSString stringWithFormat:@"%@         %@\n", arr[i], arr[i + 1]];
                content = [content stringByAppendingString:str];
            }
        }
        completed(isSuccessed,content);
    }];
}
-(void)requestSuggestsaveWithContext:(NSString*)context completed:(void(^)(NSString * codeType,NSString * errorMessage))completed{
    [[SEGSuggestsaveManager sharedManager] requestSuggestsaveWithContext:context sugType:@"1040" finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        completed(codeType,errorMessage);
    }];
}
#pragma mark - getter
@end
